import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

/**
 * User: deepal
 * Date: Dec 10, 2010
 * Time: 3:23:40 PM
 */
public class MyClient {

    public static void main(String[] args) throws AxisFault {
        if (args.length < 2) {
            System.exit(0);
        }
        String address = args[0];
        int port = Integer.parseInt(args[1]);
        MultiClient cl = new MultiClient();

        ServiceClient client = new ServiceClient();
        Options opts = new Options();
        opts.setTo(new EndpointReference("http://"+ address +":" +port+"/axis2/services/Version/getVersion"));
        client.setOptions(opts);
        opts.setProperty(Constants.Configuration.ENABLE_REST, Boolean.TRUE);
        opts.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET);
        while (true) {
            System.out.println("Send req");
            OMElement bean = client.sendReceive(createPayLoad());
            System.out.println(bean);
            System.out.println("Got rep");
        }


    }

    public static OMElement createPayLoad() {

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(
                "http://ws.apache.org/axis2", "ns");
        OMElement method = fac.createOMElement("sayHello", omNs);
        OMElement value = fac.createOMElement("name", omNs);
        method.addChild(value);
        value.setText("Axis2");
        return method;
    }
}
